﻿using System.Windows.Media;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.Charting;
using System.Windows.Controls;
using System.Windows.Data;

namespace LightSwitchApplication.UserControls.ReportChart
{
    public partial class LSWReportChart : UserControl
    {
        SolidColorBrush foreground = new SolidColorBrush(Color.FromArgb(0xff, 0x2a, 0x2a, 0x2a));
        public LSWReportChart()
        {
            InitializeComponent();

            if (StyleManager.ApplicationTheme is Office_BlackTheme)
                this.chartTitle1.Foreground = this.chartTitle2.Foreground = this.chartTitle3.Foreground = foreground;
        }

        void ChartArea2_ChartItemClick(object sender, ChartItemClickEventArgs e)
        {
            (this.DataContext as SalesViewModel).ChangePieData();
        }

        void ChartArea2_ItemToolTipOpening(ItemToolTip2D tooltip, ItemToolTipEventArgs e)
        {
            RadChart chart = new RadChart();
            Binding binding = new Binding("WeeklyData");
            binding.Source = this.DataContext;
            chart.SetBinding(RadChart.ItemsSourceProperty, binding);
            chart.Height = 200;
            chart.Width = 350;
            chart.DefaultView.ChartLegend.Visibility = System.Windows.Visibility.Collapsed;
            chart.DefaultView.ChartTitle.Content = "Thông tin mỗi tuần";
            chart.DefaultView.ChartArea.AxisY.DefaultLabelFormat = "C0";
            chart.DefaultView.ChartArea.AxisX.LayoutMode = AxisLayoutMode.Inside;

            SeriesMapping _seriesMapping = new SeriesMapping();
            _seriesMapping.SeriesDefinition = new LineSeriesDefinition();
            _seriesMapping.SeriesDefinition.ShowItemLabels = false;
            _seriesMapping.ItemMappings.Add(new ItemMapping("Volume", DataPointMember.YValue));
            _seriesMapping.ItemMappings.Add(new ItemMapping("Category", DataPointMember.XCategory));
            chart.SeriesMappings.Add(_seriesMapping);

            tooltip.Content = chart;
        }
    }
}
